package com.hyj.ecp.backstage.cust.service.impl;

import java.util.*;

import javax.annotation.Resource;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Service;

import com.ecp.cust.ClientUserQO;
import com.hyj.ecp.backstage.cust.service.ICustService;
import com.hyj.ecp.common.dao.IjdbcDAO;

@Service
public class CustService implements ICustService {

	@Resource(name="jdbcDao")
    private  IjdbcDAO dao;
	
	@Override
	public Map<String,Object> queryClientUsers(ClientUserQO qo) {
		/*int a = PaginationHelper.getRowCount(dao, "com.ecp.backstage.cust.queryClientUsers", qo);
		System.out.println(a);
		
		List<ClientUserQO> list=  session.selectList("com.ecp.backstage.cust.queryClientUsers",qo);*/
		List<Object> param = new ArrayList<Object>();
		String sql = "    SELECT  t.id,t.account,t.abbrname,t.name,t.cardno,t.mobile,t.phone FROM   t_client_user t  where  1=1 ";
		if(qo.getName()!=null&&qo.getName().length()>0){
			sql= sql+" and t.name = ? ";
			param.add(qo.getName());
		}
		
		if(qo.getAccount()!=null&&qo.getAccount().length()>0){
			sql= sql+" and t.account = ? ";
			param.add(qo.getAccount());
		}
		
		int a = dao.queryCount(sql, param.toArray());
		//List<ClientUserQO> list= dao.queryForList(sql, qo.getCurPage(), qo.getSize(),  new Object[]{},ClientUserQO.class);
		List<Map<String,Object>> list= dao.queryForList(sql, qo.getCurPage(), qo.getSize(),  param.toArray()); 
		Map<String,Object> vo = new HashMap<String,Object>();
    	vo.put("rowTotal", a);
    	vo.put("infoContent", list);
		return  vo;
	}

	@Override
	public Map<String, Object> queryCustCustProblem(ClientUserQO qo) {
		List<Object> param = new ArrayList<Object>();
		String sql = "    SELECT t.id, t.account,t.msg,t.addtime FROM   t_cust_problem t  where  1=1 ";
		
		if(qo.getAccount()!=null&&qo.getAccount().length()>0){
			sql= sql+" and t.account = ? ";
			param.add(qo.getAccount());
		}
		
		int a = dao.queryCount(sql, param.toArray());
		//List<ClientUserQO> list= dao.queryForList(sql, qo.getCurPage(), qo.getSize(),  new Object[]{},ClientUserQO.class);
		List<Map<String,Object>> list= dao.queryForList(sql, qo.getCurPage(), qo.getSize(),  param.toArray()); 
		Map<String,Object> vo = new HashMap<String,Object>();
    	vo.put("rowTotal", a);
    	vo.put("infoContent", list);
		return  vo;
	}

	@Override
	public  Map<String, Object> toViewcust(ClientUserQO qo) {
		
		 if(qo.getAccount()==null){
			 return null;
		 }
		
         String sql = "   SELECT t.*,IFNULL(p.POINT,0) AS totalPoint,IFNULL(p.MONEY,0) AS TOTALMONEY,IFNULL(p.HMoney,0) AS totalHbi " + 
         		"		FROM t_client_user t " + 
         		"		LEFT OUTER JOIN t_cust_point  p " + 
         		"		ON t.ACCOUNT=p.ACCOUNT " + 
         		"		WHERE    t.ACCOUNT=?  limit 0,1";
         return dao.queryForMap(sql, new Object[]{qo.getAccount()});
		 
		 
	}
}
